# 定义收据相关信息
order_number = "DH202311010001"
time = "2023-11-01 20:56:15"
discount_rate = 0.9  # 9折优惠，1.0表示无折扣

items = [
    {"name": "金士顿U盘8G", "quantity": 1, "unit_price": 40.00},
    {"name": "胜创16GTF卡", "quantity": 1, "unit_price": 50.00},
    {"name": "读卡器", "quantity": 1, "unit_price": 8.00},
    {"name": "网线2米", "quantity": 1, "unit_price": 5.00},
    {"name": "拼好饭", "quantity": 2, "unit_price": 20.00}
]

# 计算每个商品的金额
for item in items:
    item["amount"] = item["quantity"] * item["unit_price"]

# 计算总数和总额
total_count = sum(item["quantity"] for item in items)
total_amount = sum(item["amount"] for item in items)

# 计算折扣金额和折后总额
discount_amount = total_amount * (1 - discount_rate)
discounted_total = total_amount * discount_rate

# 收款和找零
received = 100.00  # 假设实收金额
change = received - discounted_total
cashier = "管理员"

# 打印收据
print("=" * 40)
print(f"单号: {order_number:>28}")
print(f"时间: {time:>28}")
print("-" * 40)

# 打印商品列表标题
print(f"{'名称':<15}{'数量':<8}{'单价':<8}{'金额':<8}")
for item in items:
    print(f"{item['name']:<15}{item['quantity']:<8}{item['unit_price']:<8.2f}{item['amount']:<8.2f}")
print("-" * 40)

# 打印折扣信息
print(f"折扣率: {discount_rate*10:.1f}折")
print(f"折扣金额: {discount_amount:.2f}")
print("-" * 40)

# 打印总数、总额等信息
print(f"总数: {total_count:>33}")
print(f"总额: {total_amount:>32.2f}")
print(f"折后总额: {discounted_total:>28.2f}")
print(f"实收: {received:>32.2f}")
print(f"找零: {change:>32.2f}")
print(f"收银: {cashier:>32}")
print("=" * 40)
    


